package com.cskaoyan.service.wxcatalog;

import com.cskaoyan.bean.MarketCategory;
import com.cskaoyan.bean.MarketCategoryExample;
import com.cskaoyan.bean.category.CategoryExample;
import com.cskaoyan.bean.vxcatalogvo.VXCatalogCurrentVO;
import com.cskaoyan.bean.vxcatalogvo.VXCatalogIndexVO;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 创建日期: 2022/05/08 21:27
 *
 * @author shuyang
 */
@Service
public class WXCatalogServiceImpl implements WXCatalogService {
    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Override
    public VXCatalogIndexVO selectCatalogIndexInVX() {
        //   pid为0表示为分类根目录
        int rootPid = 0;
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andPidEqualTo(rootPid);
        criteria.andDeletedEqualTo(false);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        //第1个元素为当前页面默认显示额元素
        MarketCategory marketCategory = marketCategories.get(0);
        Integer id = marketCategory.getId();
        MarketCategoryExample marketCategoryExample1 = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria1 = marketCategoryExample1.createCriteria();
        criteria1.andPidEqualTo(id);
        criteria1.andDeletedEqualTo(false);
        List<MarketCategory> marketCategories1 = marketCategoryMapper.selectByExample(marketCategoryExample1);
        VXCatalogIndexVO vxCatalogIndexVO = new VXCatalogIndexVO(marketCategories,marketCategory,marketCategories1);
        return vxCatalogIndexVO;
    }

    @Override
    public VXCatalogCurrentVO selectCatalogCurrentInVX(Integer id) {
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andPidEqualTo(id);
        criteria.andDeletedEqualTo(false);
        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(id);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        return new VXCatalogCurrentVO(marketCategory, marketCategories);
    }
}
